//
//  UserNameViewController.m
//  WhatsChat
//
//  Created by 彭琦峰 on 16/3/23.
//  Copyright © 2016年 tanchen. All rights reserved.
//

#import "UserNameViewController.h"
#import "PersonViewController.h"
#import <AVOSCloud/AVOSCloud.h>

@interface UserNameViewController ()

@property (nonatomic,strong)UITextField *userNameTextField;
@property (nonatomic,strong)UILabel *messageLabel;
@property (nonatomic,strong)UILabel *label;
@property (nonatomic,strong)AVObject *UserName;
@property (nonatomic,strong)NSString *string;


@end

@implementation UserNameViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    //设置字体颜色
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    
    //视图布局
    [self initLayout];
    
}
//保存点击事件
- (void)saveAction{
    
    
    
#pragma make=========往服务器上存储数据====================
    
//    self.string = self.userNameTextField.text;
//    
//    NSString *currentUsername = [AVUser currentUser].username;// 当前用户名
//
//    self.UserName = [[AVObject alloc] initWithClassName:@"UserName"];// 构建对象
//     //只要添加这一行代码，服务端就会自动添加这个字段
//    [self.UserName setObject:self.string forKey:[NSString stringWithFormat:@"name%@",currentUsername]];
//    
//    [self.UserName saveInBackground];
//    
//    NSArray *array = [self.UserName allKeys];
//    
//    AVQuery *query = [AVQuery queryWithClassName:@"UserName"];
//    
//    if ([array[0] isEqualToString:[NSString stringWithFormat:@"name%@",currentUsername]]) {
//        
//        [[query getFirstObject] deleteInBackground];
//        
//    }
    
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)initLayout{

    self.userNameTextField = [[UITextField alloc]initWithFrame:CGRectMake(20, 84, self.view.width - 40, 40)];
    
    self.userNameTextField.text = [[NSUserDefaults standardUserDefaults]objectForKey:@"name"];
    //添加到view上
    [self.view addSubview:self.userNameTextField];
    
    self.label = [[UILabel alloc]initWithFrame:CGRectMake(20, 124, self.view.width - 40, 2)];
    self.label.backgroundColor = [UIColor greenColor];
    [self.view addSubview:self.label];
    
    self.messageLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 126, self.view.width - 40, 40)];
    self.messageLabel.text = @"好名字可以让你的朋友更好的记住你";
    [self.view addSubview:self.messageLabel];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"保存" style:UIBarButtonItemStyleDone target:self action:@selector(saveAction)];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
